home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0833.dms / q0833.adf / CalenderMacros / calendar.fw2 next >
Text File  |  1997-04-10  |  12KB  |  344 lines

  1. /* Calendar macro for FinalWriter (SoftWood)
  2.    Written by Andrew McCardie
  3.    amethyst@gulf.net
  4.    November 29th, 1994
  5.    $VER: FW Calendar Macro v1.1 for FW2.x
  6.  
  7.    This macro works only under FinalWriter version 2.x.  FW3
  8.    is supported in the other macro in this archive.
  9.  
  10.    This macro can create three different types of calendars: Portrait,
  11.    double-portrait, and landscape.  It supports all years that are
  12.    supported by the Amiga's internal calendar (1978 ->)  
  13.  
  14.    Portrait produces a standard 8.5x11 page with a single calendar.
  15.    Double portrait produces a standard 8.5x11 page with two calendars.
  16.    Landscape produces a standard 11x8.5 page with a single calendar.
  17.  
  18.    While it should handle leap-years, this feature has not been
  19.    exhaustively tested.  The fonts and margins are designed to be
  20.    user-customizeable.  Certain default values (in inches) have been
  21.    hardcoded into the variables 'top_margin', 'bottom_margin', and 
  22.    'side_margin' to produce the largest calendars on my DeskJet.  You
  23.    can change these if you need a smaller calendar or if the calendars
  24.    print incorrectly on your setup.
  25.  
  26.    If you change the default fonts, you may have to experiment with their
  27.    sizes and widths to get an appropriate look.
  28.  
  29.    If you find any bugs, let me know and I'll try to rectify them.
  30.  
  31.    Disclaimer: I take no responsibility for problems that may result from using
  32.             this macro.  
  33. */
  34.  
  35. OPTIONS RESULTS
  36. ADDRESS "FINALW.1"
  37. ClearDoc FORCE
  38. View 25  /* Speeds things up slightly on fast machines, probably more on
  39.           slower machines.
  40.         */
  41. SetMeasure MicroPoints
  42. BoxPrefs LINEWT 2 LINECOLOR Black FILL Solid FILLCOLOR Cyan TEXTFLOW None
  43.  
  44. TextBlockPrefs TEXTFLOW None
  45.  
  46. micropoints_per_inch = 720
  47.  
  48. ShowMessage 1 0 '"What type of calendar?" "" "" "Portrait" "Double-Portrait" "Landscape"'
  49. calendar_type = RESULT
  50.  
  51. Select
  52.  
  53.     /*  Portrait calendar  */
  54.    When calendar_type = 1 Then
  55.       Do
  56.          PageSetup PAGETYPE USLetter ORIENT Tall
  57.          GetPageSetup WIDTH HEIGHT
  58.             Parse Var RESULT true_width true_height
  59.  
  60.             /* The following measurements are based on inches converted to micropoints
  61.                Experiment with the defaults at your own risk, however. :) */
  62.  
  63.             side_margin = Trunc(.5 * micropoints_per_inch)
  64.             top_margin = Trunc(.625 * micropoints_per_inch)
  65.             bottom_margin = Trunc(.625 * micropoints_per_inch)
  66.             pagewidth = Trunc(true_width - 2 * side_margin)
  67.             pageheight = Trunc(true_height - top_margin - bottom_margin)
  68.             text_area = Trunc(.15 * pageheight) /* 15% of calendar size devoted to titles */
  69.             boxwidth = Trunc(pagewidth/7)
  70.             boxheight = Trunc((pageheight-text_area)/5)
  71.             bevel_control = "BEVEL"
  72.             SectionSetup TOP top_margin INSIDE side_margin OUTSIDE side_margin
  73.  
  74.             /* Set up font defaults */
  75.             datestring_font = "Dragon_BoldItalic"
  76.             datestring_font_size = 64
  77.             datestring_font_width = 100
  78.             text_font = "Dragon_BoldItalic"
  79.             text_font_size = 20
  80.             text_font_width = 80
  81.             day_font = "Dragon_Bold"
  82.             day_font_size = 20
  83.             day_font_width = 100
  84.  
  85.          iteration = 1
  86.         End
  87.  
  88.     /*  Double-portrait calendar  */
  89.    When calendar_type == 2 Then
  90.       Do
  91.          PageSetup PAGETYPE USLetter ORIENT Tall
  92.          GetPageSetup WIDTH HEIGHT
  93.             Parse Var RESULT true_width true_height
  94.  
  95.             /* The following measurements are based on inches converted to micropoints
  96.                Experiment with the defaults at your own risk, however. :) */
  97.  
  98.             side_margin = Trunc(.5 * micropoints_per_inch)
  99.             top_margin = Trunc(.625 * micropoints_per_inch)
  100.             bottom_margin = Trunc(5.50 * micropoints_per_inch)
  101.             pagewidth = Trunc(true_width - 2 * side_margin)
  102.             pageheight = Trunc(true_height - top_margin - bottom_margin)
  103.             text_area = Trunc(.15 * pageheight) /* 15% of calendar size devoted to titles */
  104.             boxwidth = Trunc(pagewidth/7)
  105.             boxheight = Trunc((pageheight-text_area)/5)
  106.             bevel_control = "BEVEL"
  107.             SectionSetup TOP top_margin INSIDE side_margin OUTSIDE side_margin
  108.  
  109.             /* Set up font defaults */
  110.             datestring_font = "Dragon_BoldItalic"
  111.             datestring_font_size = 34
  112.             datestring_font_width = 150
  113.             text_font = "Dragon_BoldItalic"
  114.             text_font_size = 20
  115.             text_font_width = 80
  116.             day_font = "Dragon_Bold"
  117.             day_font_size = 20
  118.             day_font_width = 100
  119.  
  120.          iteration = 2
  121.       End
  122.  
  123.     /*  Landscape calendar  */
  124.    When calendar_type == 3 Then
  125.       Do
  126.          PageSetup PAGETYPE USLetter ORIENT Wide
  127.          GetPageSetup WIDTH HEIGHT
  128.             Parse Var RESULT true_width true_height
  129.  
  130.             /* The following measurements are based on inches converted to micropoints
  131.                Experiment with the defaults at your own risk, however. :) */
  132.  
  133.             side_margin = Trunc(.5 * micropoints_per_inch)
  134.             top_margin = Trunc(.625 * micropoints_per_inch)
  135.             bottom_margin = Trunc(.625 * micropoints_per_inch)
  136.             pagewidth = Trunc(true_width - 2 * side_margin)
  137.             pageheight = Trunc(true_height - top_margin - bottom_margin)
  138.             text_area = Trunc(.15 * pageheight) /* 15% of calendar size devoted to titles */
  139.             boxwidth = Trunc(pagewidth/7)
  140.             boxheight = Trunc((pageheight-text_area)/5)
  141.             bevel_control = "BEVEL"
  142.             SectionSetup TOP top_margin INSIDE side_margin OUTSIDE side_margin
  143.  
  144.             /* Set up font defaults */
  145.             datestring_font = "Montreal_BoldItalic"
  146.             datestring_font_size = 44
  147.             datestring_font_width = 150
  148.             text_font = "Montreal_BoldItalic"
  149.             text_font_size = 22
  150.             text_font_width = 80
  151.             day_font = "Montreal_Bold"
  152.             day_font_size = 20
  153.             day_font_width = 100
  154.  
  155.          iteration = 1
  156.       End
  157. End
  158.  
  159. current_month = -1
  160. current_month_number = -1
  161. current_year = -1
  162.  
  163. temp_date = "00000000"
  164.  
  165. day.0 = 'Saturday'
  166. day.1 = 'Sunday'
  167. day.2 = 'Monday'
  168. day.3 = 'Tuesday'
  169. day.4 = 'Wednesday'
  170. day.5 = 'Thursday'
  171. day.6 = 'Friday'
  172.  
  173. month.0  = 'January'
  174. month.1  = 'February'
  175. month.2  = 'March'
  176. month.3  = 'April'
  177. month.4  = 'May'
  178. month.5  = 'June'
  179. month.6  = 'July'
  180. month.7  = 'August'
  181. month.8  = 'September'
  182. month.9  = 'October'
  183. month.10 = 'November'
  184. month.11 = 'December'
  185.  
  186. month_length.0  = 31
  187. month_length.1  = 28
  188. month_length.2  = 31
  189. month_length.3  = 30
  190. month_length.4  = 31
  191. month_length.5  = 30
  192. month_length.6  = 31
  193. month_length.7  = 31
  194. month_length.8  = 30
  195. month_length.9  = 31
  196. month_length.10 = 30
  197. month_length.11 = 31
  198.  
  199. RequestText '"Month Select" "Month:" 'DATE('M')''
  200. current_month = RESULT
  201.  
  202. RequestText '"Year Select" "Year:" 'SUBSTR(DATE('S'),1,4)''
  203. current_year = RESULT
  204. if current_year < 1978 then current_year = 1978
  205.  
  206. Do i = 0 to 11
  207.    If current_month = month.i Then current_month_number = i + 1
  208. End
  209.  
  210. Do While iteration > 0
  211.  
  212.    If current_year//4 == 0 & current_year//100 > 0 Then
  213.       month_length.1 = 29
  214.    Else
  215.       If current_year//400 == 0 Then
  216.          month_length.1 = 29
  217.  
  218.    Select
  219.       When current_month_number < 10 Then
  220.          temp_date = current_year || 0 || current_month_number || "01"
  221.       When current_month_number >= 10 Then
  222.          temp_date = current_year || current_month_number || "01"
  223.        When current_month_number == -1 Then
  224.          Exit 10
  225.    End
  226.  
  227.    first_day_of_the_month = Date('W', temp_date, 'S')
  228.  
  229.    Select
  230.       When first_day_of_the_month == "Saturday" Then cal_start = 0
  231.       When first_day_of_the_month == "Sunday" Then cal_start = 1
  232.       When first_day_of_the_month == "Monday" Then cal_start = 2
  233.       When first_day_of_the_month == "Tuesday" Then cal_start = 3
  234.       When first_day_of_the_month == "Wednesday" Then cal_start = 4
  235.       When first_day_of_the_month == "Thursday" Then cal_start = 5
  236.       When first_day_of_the_month == "Friday" Then cal_start = 6
  237.    End
  238.  
  239.    /*  Create month/year header  */
  240.    TextBlockTypePrefs SIZE datestring_font_size WIDTH datestring_font_width FONT datestring_font
  241.    datestring = current_month || " " || current_year
  242.    DrawTextBlock 1 side_margin top_margin datestring
  243.    datestring_obj = RESULT
  244.    GetObjectCoords datestring_obj
  245.    coords = RESULT
  246.    Parse Var coords Page obj_left obj_top obj_width obj_height
  247.    text_edge = Trunc(side_margin + (pagewidth - obj_width)/2)
  248.    SetObjectCoords datestring_obj Page text_edge obj_top obj_width obj_height
  249.  
  250.    i = 0
  251.    Do While (i < 7)
  252.       j = 0
  253.       box_left = side_margin+boxwidth*i
  254.       box_top = top_margin+text_area
  255.       TextBlockTypePrefs SIZE text_font_size WIDTH text_font_width FONT text_font
  256.       DrawTextBlock 1 box_left box_top-text_font_size*11 day.i
  257.       text_obj.i = RESULT
  258.       GetObjectCoords text_obj.i
  259.       coords = RESULT
  260.       Parse Var coords Page obj_left obj_top obj_width obj_height
  261.       text_edge = Trunc(box_left + (boxwidth - obj_width)/2)
  262.       SetObjectCoords text_obj.i Page text_edge obj_top obj_width obj_height
  263.       Do While (j < 5)
  264.          serial_position = i + (j * 7)
  265.          index = current_month_number - 1
  266.          If serial_position >= cal_start & serial_position < cal_start+month_length.index
  267.             Then BoxPrefs LINEWT 2 LINECOLOR Black FILL Transparent TEXTFLOW None
  268.          Else BoxPrefs LINEWT 2 LINECOLOR Black FILL Solid FILLCOLOR Cyan TEXTFLOW None
  269.          box_top  = top_margin+text_area+boxheight*j
  270.          DrawBox 1 box_left box_top boxwidth boxheight bevel_control
  271.          box_obj.i.j = RESULT
  272.          day_of_month = serial_position-cal_start+1
  273.          TextBlockTypePrefs SIZE day_font_size WIDTH day_font_width FONT day_font
  274.          GetBoxPrefs FILL
  275.          If RESULT = "Transparent" Then
  276.             If day_of_month < 10 Then
  277.                DrawTextBlock 1 box_left+boxwidth-200 box_top+boxheight-200 day_of_month
  278.             Else
  279.                DrawTextBlock 1 box_left+boxwidth-300 box_top+boxheight-200 day_of_month
  280.          Else NOP
  281.          j = j + 1
  282.       End
  283.       i = i + 1
  284.    End
  285.  
  286.     /* Special cases for months whose last day(s) wrap to the 
  287.        beginning of the week */
  288.  
  289.    If cal_start+month_length.index == 36 Then
  290.       Do
  291.          day_of_month = day_of_month + 1
  292.          GetObjectCoords box_obj.0.4
  293.          coords = RESULT
  294.          Parse Var coords Page obj_left obj_top obj_width obj_height
  295.          DrawLine Page obj_left+40 obj_top+obj_height-40 obj_left+obj_width-40 obj_top+40
  296.          DrawTextBlock 1 obj_left+50 obj_top+50 day_of_month
  297.       End
  298.    If cal_start+month_length.index == 37 Then
  299.       Do
  300.          day_of_month = day_of_month + 1
  301.          GetObjectCoords box_obj.0.4
  302.          coords = RESULT
  303.          Parse Var coords Page obj_left obj_top obj_width obj_height
  304.          DrawLine Page obj_left+40 obj_top+obj_height-40 obj_left+obj_width-40 obj_top+40
  305.          DrawTextBlock 1 obj_left+50 obj_top+50 day_of_month
  306.          day_of_month = day_of_month + 1
  307.          GetObjectCoords box_obj.1.4
  308.          coords = RESULT
  309.          Parse Var coords Page obj_left obj_top obj_width obj_height
  310.          DrawLine Page obj_left+40 obj_top+obj_height-40 obj_left+obj_width-40 obj_top+40
  311.          DrawTextBlock 1 obj_left+50 obj_top+50 day_of_month
  312.       End
  313.  
  314.    /*  Handles special case of double portrait calendar  */
  315.     If iteration == 2 Then
  316.       Do
  317.          drop datestring
  318.             top_margin = Trunc(5.5 * micropoints_per_inch)
  319.             bottom_margin = Trunc(.625 * micropoints_per_inch)
  320.             pagewidth = Trunc(true_width - 2 * side_margin)
  321.             pageheight = Trunc(true_height - top_margin - bottom_margin)
  322.             text_area = Trunc(.15 * pageheight) /* 15% of calendar size devoted to titles */
  323.             boxwidth = Trunc(pagewidth/7)
  324.             boxheight = Trunc((pageheight-text_area)/5)
  325.          If current_month_number < 12 Then
  326.             Do
  327.                current_month = month.current_month_number
  328.                current_month_number = current_month_number + 1
  329.             End
  330.          Else
  331.             Do
  332.                current_month_number = 1
  333.                current_month = "January"
  334.                     current_year = current_year + 1
  335.             End
  336.       End
  337.     iteration = iteration - 1
  338. End
  339.  
  340. SectionSetup BOTTOM bottom_margin
  341. SelectObject
  342. Redraw
  343. View 50
  344.